{% extends "admin/base_site.html" %}
{% load i18n static admin_urls %}

{% block extrastyle %}
  {{ block.super }}
  <link rel="stylesheet" href="{% static "css/admin_custom.css" %}">
  <style>
    .dashboard-container {
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      margin-bottom: 20px;
    }
    
    .dashboard-card {
      flex: 1;
      min-width: 200px;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
      background-color: #fff;
      text-align: center;
    }
    
    .dashboard-card h3 {
      margin-top: 0;
      color: #666;
    }
    
    .dashboard-card .count {
      font-size: 2.5rem;
      font-weight: bold;
      color: #1a73e8;
    }
    
    .recent-actions {
      background-color: #fff;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .recent-actions h2 {
      margin-top: 0;
      border-bottom: 2px solid #f0f0f0;
      padding-bottom: 10px;
    }
    
    .recent-events {
      background-color: #fff;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
      margin-bottom: 20px;
    }
    
    .recent-events h2 {
      margin-top: 0;
      border-bottom: 2px solid #f0f0f0;
      padding-bottom: 10px;
    }
    
    .event-list {
      list-style-type: none;
      padding: 0;
    }
    
    .event-list li {
      padding: 10px 0;
      border-bottom: 1px solid #f0f0f0;
    }
    
    .event-list li:last-child {
      border-bottom: none;
    }
    
    .event-time {
      color: #666;
      font-size: 0.9rem;
    }
  </style>
{% endblock %}

{% block extrahead %}
  {{ block.super }}
  <script src="{% static "js/admin_custom.js" %}"></script>
{% endblock %}

{% block coltype %}colMS{% endblock %}

{% block bodyclass %}{{ block.super }} dashboard{% endblock %}

{% block content %}
<div id="content-main">
  <!-- 概览统计卡片 -->
  <div class="dashboard-container">
    <div class="dashboard-card">
      <h3>展区</h3>
      <div class="count">{{ areas_count }}</div>
      <a href="{% url 'admin:airshow_area_changelist' %}" class="button">管理展区</a>
    </div>
    
    <div class="dashboard-card">
      <h3>参展商</h3>
      <div class="count">{{ exhibitors_count }}</div>
      <a href="{% url 'admin:airshow_exhibitor_changelist' %}" class="button">管理参展商</a>
    </div>
    
    <div class="dashboard-card">
      <h3>展品</h3>
      <div class="count">{{ exhibits_count }}</div>
      <a href="{% url 'admin:airshow_exhibit_changelist' %}" class="button">管理展品</a>
    </div>
    
    <div class="dashboard-card">
      <h3>活动</h3>
      <div class="count">{{ events_count }}</div>
      <a href="{% url 'admin:airshow_schedule_changelist' %}" class="button">管理活动</a>
    </div>
    
    <div class="dashboard-card">
      <h3>观众</h3>
      <div class="count">{{ audience_count }}</div>
      <a href="{% url 'admin:airshow_audience_changelist' %}" class="button">管理观众</a>
    </div>
  </div>
  
  <!-- 最近活动 -->
  {% if recent_events %}
  <div class="recent-events">
    <h2>最近活动</h2>
    <ul class="event-list">
      {% for event in recent_events %}
      <li>
        <a href="{% url 'admin:airshow_schedule_change' event.event_id %}">{{ event.title }}</a>
        <div class="event-time">{{ event.event_time }}</div>
      </li>
      {% endfor %}
    </ul>
  </div>
  {% endif %}

  <!-- 应用列表 -->
  {% if app_list %}
    <div class="app-list">
      {% for app in app_list %}
        <div class="app-item module{% if app.app_url in request.path|urlencode %} current-app{% endif %}">
          <table>
            <caption>
              <a href="{{ app.app_url }}" class="section" title="{% blocktranslate with name=app.name %}Models in the {{ name }} application{% endblocktranslate %}">{{ app.name }}</a>
            </caption>
            {% for model in app.models %}
              <tr class="model-{{ model.object_name|lower }}{% if model.admin_url in request.path|urlencode %} current-model{% endif %}">
                {% if model.admin_url %}
                  <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
                {% else %}
                  <th scope="row">{{ model.name }}</th>
                {% endif %}

                {% if model.add_url %}
                  <td><a href="{{ model.add_url }}" class="addlink">{% translate 'Add' %}</a></td>
                {% else %}
                  <td></td>
                {% endif %}

                {% if model.admin_url and show_changelinks %}
                  {% if model.view_only %}
                    <td><a href="{{ model.admin_url }}" class="viewlink">{% translate 'View' %}</a></td>
                  {% else %}
                    <td><a href="{{ model.admin_url }}" class="changelink">{% translate 'Change' %}</a></td>
                  {% endif %}
                {% elif show_changelinks %}
                  <td></td>
                {% endif %}
              </tr>
            {% endfor %}
          </table>
        </div>
      {% endfor %}
    </div>
  {% else %}
    <p>{% translate "You don't have permission to view or edit anything." %}</p>
  {% endif %}

  <!-- 最近动作 -->
  <div class="recent-actions">
    <h2>{% translate 'Recent actions' %}</h2>
    {% load log %}
    {% get_admin_log 10 as admin_log for_user user %}
    {% if not admin_log %}
      <p>{% translate 'None available' %}</p>
    {% else %}
      <ul class="actionlist">
        {% for entry in admin_log %}
          <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">
            {% if entry.is_deletion or not entry.get_admin_url %}
              {{ entry.object_repr }}
            {% else %}
              <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
            {% endif %}
            <br>
            {% if entry.content_type %}
              <span class="mini quiet">{% filter capfirst %}{{ entry.content_type.name }}{% endfilter %}</span>
            {% else %}
              <span class="mini quiet">{% translate 'Unknown content' %}</span>
            {% endif %}
          </li>
        {% endfor %}
      </ul>
    {% endif %}
  </div>
</div>
{% endblock %}

{% block sidebar %}
<div id="content-related">
    <div class="module" id="quick-links">
        <h2>{% translate 'Quick links' %}</h2>
        <ul>
            <li><a href="{% url 'admin:airshow_area_changelist' %}">展区管理</a></li>
            <li><a href="{% url 'admin:airshow_exhibitor_changelist' %}">参展商管理</a></li>
            <li><a href="{% url 'admin:airshow_exhibit_changelist' %}">展品管理</a></li>
            <li><a href="{% url 'admin:airshow_schedule_changelist' %}">活动日程管理</a></li>
            <li><a href="{% url 'admin:airshow_attendance_changelist' %}">参与记录管理</a></li>
            <li><a href="{% url 'admin:auth_user_changelist' %}">用户管理</a></li>
        </ul>
        
        <h2>{% translate 'System info' %}</h2>
        <ul>
            <li>版本: {{ version }}</li>
            <li>当前用户: {{ request.user.username }}</li>
        </ul>
    </div>
</div>
{% endblock %} 